//思路： 先算出两个单链表的长度，然后指针对齐向后找到指针相同；
import java.util.List;

public class Solution {
    public static void main(String[] args) {

        }


    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int count1=0,count2=0;
        ListNode p=headA;
        while(p!=null){
            p=p.next;
            count1++;
        }
        p=headB;
        while(p!=null){
            p=p.next;
            count2++;
        }
        int m=Math.max(count1,count2)-Math.min(count1,count2);
        ListNode p1=headA,p2=headB;
        for (int i = 0; i <m ; i++) {
            if (count1 - count2 > 0) p1 = p1.next ;
            else p2 = p2.next;
        }
        while(p1!=p2){
            p1=p1.next;
            p2=p2.next;
        }
        return p1;
    }

}


    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }









